﻿using System;
using System.ServiceModel;

namespace TfsGiggle.Core
{
    /// <summary>
    /// Do a search
    /// </summary>
    [ServiceContract(Namespace = "http://tfsgiggle.codeplex.com")]
    public interface ISearch
    {
        /// <summary>
        /// Do a search
        /// </summary>
        /// <param name="userQuery"></param>
        /// <returns></returns>
        [OperationContract]
        QueryResultDTO Query(string userQuery);

        /// <summary>
        /// Get number of documents in the index
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        int GetNumberOfDocuments();

        /// <summary>
        /// Get this specific document
        /// </summary>
        /// <param name="documentId"></param>
        /// <returns></returns>
        [OperationContract]
        QueryResultDTO GetDocument(int documentId);

        /// <summary>
        /// Get statistics from TfsGiggle
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        string GetStatistics();

        /// <summary>
        /// Add the changeset for the specified teamprojectcollection to the index. 
        /// See example on how to find the teamprojectcollectionid
        /// <example>
        /// $tfs = [Microsoft.TeamFoundation.Client.TfsConfigurationServerFactory]::GetConfigurationServer("http://localhost:8080/tfs")
        /// $collectionService = $tfs.GetService([Microsoft.TeamFoundation.Framework.Client.ITeamProjectCollectionService])
        /// $collectionService.GetCollections()|%{ $_.Name + ": " + $_.Id }
        /// </example>
        /// </summary>
        /// <param name="teamProjectCollectionId"></param>
        /// <param name="changesetId"></param>
        [OperationContract]
        void AddChangeset(string teamProjectCollectionId, int changesetId);
    }

    /// <summary>
    /// Do a search http://ayende.com/blog/3229/wcf-async-without-proxies
    /// </summary>
    [ServiceContract(Name = "ISearch", Namespace = "http://tfsgiggle.codeplex.com")]
    public interface IAsyncSearch
    {
        /// <summary>
        /// Do a search begin
        /// </summary>
        /// <param name="userQuery"></param>
        /// <param name="callback"></param>
        /// <param name="asyncState"></param>
        /// <returns></returns>
        [OperationContract(AsyncPattern = true)]
        IAsyncResult BeginQuery(string userQuery, AsyncCallback callback, object asyncState);

        /// <summary>
        /// Do a search end
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        QueryResultDTO EndQuery(IAsyncResult result);

        /// <summary>
        /// Get the number of documents in the index begin
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="asyncState"></param>
        /// <returns></returns>
        [OperationContract(AsyncPattern = true)]
        IAsyncResult BeginGetNumberOfDocuments(AsyncCallback callback, object asyncState);

        /// <summary>
        /// Get the number of documents in the index begin
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        int EndGetNumberOfDocuments(IAsyncResult result);

        /// <summary>
        /// Get this document begin
        /// </summary>
        /// <param name="documentId"></param>
        /// <param name="callback"></param>
        /// <param name="asyncState"></param>
        /// <returns></returns>
        [OperationContract(AsyncPattern = true)]
        IAsyncResult BeginGetDocument(int documentId, AsyncCallback callback, object asyncState);

        /// <summary>
        /// Get this document end
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        QueryResultDTO EndGetDocument(IAsyncResult result);

        /// <summary>
        /// Get statistics
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="asyncState"></param>
        /// <returns></returns>
        [OperationContract(AsyncPattern = true)]
        IAsyncResult BeginGetStatistics(AsyncCallback callback, object asyncState);

        /// <summary>
        /// Get statistics end
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        string EndGetStatistics(IAsyncResult result);

    }
}
